<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            height: 2000px;
        }
        a{
            display: none;
            position: fixed;
            bottom: 20px;
            right:20px;
        }
    </style>
</head>
<body>
    <div></div>
    <a href="#" id="back">回到顶部</a>
</body>
<script>
    //针对获取浏览器的垂直滚动条的位置
    window.onscroll = function () {
        var a = document.getElementById('back')
        console.log(document.documentElement.scrollTop)
        if(document.documentElement.scrollTop>500){
            a.style.display = 'block'
        }else{
            a.style.display = 'none'
        }
    }
</script>
</html>